package com.example.myapplication.ui.dashboard;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.example.myapplication.ChapterActivity;
import com.example.myapplication.ChatActivity;
import com.example.myapplication.LoginActivity;
import com.example.myapplication.R;

public class DashboardFragment extends Fragment {
    private DashboardViewModel dashboardViewModel;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        dashboardViewModel =
                ViewModelProviders.of(this).get(DashboardViewModel.class);
        View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
      //  final TextView textView = root.findViewById(R.id.text_dashboard);
        dashboardViewModel.getText().observe(this, new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
            //    textView.setText(s);
            }
        });



     return root;

    }



    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        Button zonghe = (Button) getActivity().findViewById(R.id.btn_mnks);
        zonghe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "综合测试", Toast.LENGTH_LONG).show();
            //从fragment跳转到activity中
                startActivity(new Intent(getActivity(), ChatActivity.class));
            }
        });

        Button until = (Button) getActivity().findViewById(R.id.btn_test2);
        until.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "章节测试", Toast.LENGTH_LONG).show();
                //从fragment跳转到activity中
                startActivity(new Intent(getActivity(), ChapterActivity.class));
            }


       });}}